package com.ello.androidskeleton.ui.tab1

import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.viewholder.BaseDataBindingHolder
import com.chad.library.adapter.base.viewholder.BaseViewHolder
import com.ello.androidskeleton.R
import com.ello.androidskeleton.databinding.FragmentTab1Binding
import com.ello.androidskeleton.databinding.ItemFuncBinding
import com.ello.androidskeleton.ui.file.FileOperationActivity
import com.ello.androidskeleton.ui.tab2.Tab2Fragment
import com.ello.base.common.BaseViewModel
import com.ello.base.common.BaseVmFragment
import com.ello.base.ktx.startActivity
import com.ello.base.view.addDivider

/**
 * @author du_xi
 * @date   2023/6/5
 */
class Tab1Fragment : BaseVmFragment<BaseViewModel, FragmentTab1Binding>() {

    companion object {
        fun newInstance() = Tab1Fragment()
    }


    private val listAdapter by lazy {
        object :
            BaseQuickAdapter<Triple<Int, String, String>, BaseDataBindingHolder<ItemFuncBinding>>(R.layout.item_func) {
            override fun convert(
                holder: BaseDataBindingHolder<ItemFuncBinding>,
                item: Triple<Int, String, String>
            ) {
                holder.dataBinding?.apply {
                    tvTitle.text = item.second
                }
            }
        }.apply {
            setOnItemClickListener { _, _, position ->
                itemClick(getItem(position))
            }
        }
    }

    private fun itemClick(item: Triple<Int, String, String>) {
        when(item.first) {
            0 -> startActivity<FileOperationActivity>()
        }
    }

    override fun initView() {
        vb.recyclerView.adapter = listAdapter
        vb.recyclerView.addDivider(showLastLine = true)
    }

    override fun initData() {
        val dataList = mutableListOf(
            Triple(0, "文件操作", "链接")
        )
        listAdapter.setList(dataList)
    }
}